
#include "SimpleSharedPtr.hh"
#include "Student.hh"
#include "Student.cpp"
#include <iostream>

int main() {
    // 使用 SimpleSharedPtr 管理 Student 对象
    SimpleSharedPtr<Student> s1(new Student("Alice", 20));

    // 测试箭头运算符
    std::cout << "=== 测试箭头运算符 ===" << std::endl;
    std::cout << "Name: " << s1->getName() << ", Age: " << s1->getAge() << std::endl;

    // 测试解引用运算符
    std::cout << "\n=== 测试解引用运算符 ===" << std::endl;
    (*s1).setName("Bob");
    (*s1).setAge(21);
    std::cout << "Name: " << s1->getName() << ", Age: " << s1->getAge() << std::endl;

    // 测试拷贝构造函数
    std::cout << "\n=== 测试拷贝构造函数 ===" << std::endl;
    SimpleSharedPtr<Student> s2(s1);
    std::cout << "s2 use count: " << s2.use_count() << std::endl;

    // 测试赋值运算符
    std::cout << "\n=== 测试赋值运算符 ===" << std::endl;
    SimpleSharedPtr<Student> s3(new Student("Charlie", 22));
    s3 = s1;
    std::cout << "s3 use count: " << s3.use_count() << std::endl;

    // 测试移动构造函数
    std::cout << "\n=== 测试移动构造函数 ===" << std::endl;
    SimpleSharedPtr<Student> s4(SimpleSharedPtr<Student>(new Student("David", 23)));
    std::cout << "s4 Name: " << s4->getName() << ", Age: " << s4->getAge() << std::endl;
    std::cout << "s4 use count: " << s4.use_count() << std::endl;

    // 测试 reset 方法
    std::cout << "\n=== 测试 reset 方法 ===" << std::endl;
    s4.reset(new Student("Eve", 24));
    std::cout << "s4 after reset - Name: " << s4->getName() << ", Age: " << s4->getAge() << std::endl;
    std::cout << "s4 use count after reset: " << s4.use_count() << std::endl;

    // 测试 get 方法
    std::cout << "\n=== 测试 get 方法 ===" << std::endl;
    Student* rawPtr = s4.get();
    std::cout << "Raw pointer Name: " << rawPtr->getName() << ", Age: " << rawPtr->getAge() << std::endl;

    // 测试默认构造函数
    std::cout << "\n=== 测试默认构造函数 ===" << std::endl;
    SimpleSharedPtr<Student> s5;
    std::cout << "s5 use count: " << s5.use_count() << std::endl;

    return 0;
}
